
*** Load Data
use .../cord_cutter_sample_hhlev.dta, clear

* Generate and rescale demographic variables
xtile pct_inc = d_inc, nq(4)
gen d_inc_10k = d_inc/100000
gen d_home_100k = d_home_market_value/100000
replace d_hh_avg_adultage = d_hh_avg_adultage/10
replace d_length_of_residence = d_length_of_residence/10

* Generate usage variables
gen log_gb = log(tot_gb)
gen log_video = log(level_video)

* Summary Statistics for Table 1

* 2012
su tier2012_lower tier2012_med tier2012_higher tier2012speed gb2012
su tier2012_lower tier2012_med tier2012_higher tier2012speed gb2012 if is_cordcutter
su tier2012_lower tier2012_med tier2012_higher tier2012speed gb2012 if 1-is_cordcutter

* 2015
su mode_tier_lower mode_tier_med mode_tier_higher tier2015speed tot_gb
su mode_tier_lower mode_tier_med mode_tier_higher tier2015speed if is_cordcutter
su mode_tier_lower mode_tier_med mode_tier_higher tier2015speed if 1-is_cordcutter

*** Summary Statistics for Table A1

xtile xinc=d_inc_10k, n(4)
xtile xage=d_hh_avg_adultage, n(4)
xtile xsize=d_hhsize, n(4)
gen xkids = 1*(d_hh_nchildren>0) + 1*(d_hh_nchildren>1) + 1*(d_hh_nchildren>2)

eststo xinc1: estpost tabstat tot_gb , stat(mean) by(xinc)
eststo xinc2: estpost tabstat level_browsing , stat(mean) by(xinc)
eststo xinc3: estpost tabstat level_video , stat(mean) by(xinc)
eststo xinc4: estpost tabstat level_vidnetflix , stat(mean) by(xinc)
eststo xinc5: estpost tabstat level_vidyoutube , stat(mean) by(xinc)
eststo xage1: estpost tabstat tot_gb , stat(mean) by(xage)
eststo xage2: estpost tabstat level_browsing , stat(mean) by(xage)
eststo xage3: estpost tabstat level_video , stat(mean) by(xage)
eststo xage4: estpost tabstat level_vidnetflix , stat(mean) by(xage)
eststo xage5: estpost tabstat level_vidyoutube , stat(mean) by(xage)
eststo xkids1: estpost tabstat tot_gb , stat(mean) by(xkids)
eststo xkids2: estpost tabstat level_browsing , stat(mean) by(xkids)
eststo xkids3: estpost tabstat level_video , stat(mean) by(xkids)
eststo xkids4: estpost tabstat level_vidnetflix , stat(mean) by(xkids)
eststo xkids5: estpost tabstat level_vidyoutube , stat(mean) by(xkids)

esttab xinc1 xinc2 xinc3 xinc4 xinc5, cells(mean(fmt(3))) unstack mtitles("Tot GB" "Browsing GB" "Vid GB" "Netflix GB" "YouTube GB")
esttab xage1 xage2 xage3 xage4 xage5 , cells(mean(fmt(3))) unstack mtitles("Tot GB" "Browsing GB" "Vid GB" "Netflix GB" "YouTube GB")
esttab xkids1 xkids2 xkids3 xkids4 xkids5 , cells(mean(fmt(3))) unstack mtitles("Tot GB" "Browsing GB" "Vid GB" "Netflix GB" "YouTube GB")

*** Regressions for Table 2

reg log_gb d_hhsize d_hh_avg_adultage d_length_of_residence d_inc_10k
est store log_gb1
reg log_gb d_hhsize d_hh_avg_adultage d_length_of_residence d_inc_10k mode_vid mode_tel mode_tier_lower mode_tier_higher
est store log_gb2

reg log_video d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k
est store log_vidgb1
reg log_video d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k mode_vid mode_tel mode_tier_lower mode_tier_higher
est store log_vidgb2

*** Regressions for Table 3

probit is_cordcutter d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k d_home_100k
eststo cc1: margins, dydx(*) post
probit is_cordcutter d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k d_home_100k log_gb log_video
eststo cc2: margins, dydx(*) post
probit is_cordcutter d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k d_home_100k log_gb log_video mode_tel mode_tier_lower mode_tier_higher
eststo cc3: margins, dydx(*) post

*** Regressions for Table A2

oprobit mode_tier_2 d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k
eststo demotier1: margins, dydx(*) predict(outcome(1)) post
oprobit mode_tier_2 d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k
eststo demotier2: margins, dydx(*) predict(outcome(2)) post
oprobit mode_tier_2 d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k
eststo demotier3: margins, dydx(*) predict(outcome(3)) post
probit mode_vid d_hhsize d_hh_avg_adultage d_hh_nchildren d_length_of_residence d_inc_10k d_home_100k
eststo demovid: margins, dydx(*) post

*** Label Variables
label variable pct_inc "Income Quartile"
label variable d_inc_10k "Income"
label variable d_home_100k "Home Value"
label variable d_hh_avg_adultage "Average Adult Age"
label variable d_hh_nchildren "Number of Children"
label variable d_hhsize "Household Size"
label variable d_length_of_residence "Tenure at Address"
label variable mode_vid "TV Subscriber"
label variable mode_tel "Phone Subscriber"
label variable mode_tier "Internet Tier"
label variable mode_tier_lower "Below Median Internet Tier"
label variable mode_tier_higher "Above Median Internet Tier"
label variable log_gb "Log Daily Internet Use"
label variable log_video "Log Daily OTT Use"

*** Output Tables to Latex
esttab log_gb1 log_gb2 log_vidgb1 log_vidgb2 ///
	using ".../demo_usage.tex", ///
	b(3) se(3) r2 label replace nomtitles nonotes ///
	noomitted nogap unstack star(* 0.10 ** 0.05 *** 0.01) booktabs ///
	mgroups("Log Total GB" "Log Streaming GB", pattern(1 0 1 0 ) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 

esttab demotier1 demotier2 demotier3 demovid ///
	using ".../demo_plan.tex", ///
	b(3) se(3) label replace mtitles("Below Median" "Median" "Above Median" "") nonotes nonumbers ///
	noomitted nogap unstack star(* 0.10 ** 0.05 *** 0.01) booktabs ///
	mgroups("Internet" "TV", pattern(1 0 0 1) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 

esttab cc1 cc2 cc3 ///
	using ".../demo_cc.tex", ///
	b(3) se(3) label replace nomtitles nonotes ///
	noomitted nogap unstack star(* 0.10 ** 0.05 *** 0.01) booktabs ///
